package com.hezhi.project.module.parent.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hezhi.project.module.parent.domain.Parent;
import com.hezhi.project.module.parent.service.IParentService;
import com.hezhi.framework.web.controller.BaseController;
import com.hezhi.framework.web.page.TableDataInfo;
import com.hezhi.framework.web.domain.AjaxResult;

/**
 * 家长 信息操作处理
 * 
 * @author hezhi
 * @date 2018-08-06
 */
@Controller
@RequestMapping("/module/parent")
public class ParentController extends BaseController
{
    private String prefix = "module/parent";
	
	@Autowired
	private IParentService parentService;
	
	@RequiresPermissions("module:parent:view")
	@GetMapping()
	public String parent()
	{
	    return prefix + "/parent";
	}
	
	/**
	 * 查询家长列表
	 */
	@RequiresPermissions("module:parent:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Parent parent)
	{
		startPage();
        List<Parent> list = parentService.selectParentList(parent);
		return getDataTable(list);
	}
	
	/**
	 * 新增家长
	 */
	@RequiresPermissions("module:parent:add")
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改家长
	 */
	@RequiresPermissions("module:parent:edit")
	@GetMapping("/edit/{parentId}")
	public String edit(@PathVariable("parentId") Integer parentId, Model model)
	{
		Parent parent = parentService.selectParentById(parentId);
		model.addAttribute("parent", parent);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存家长
	 */
	@RequiresPermissions("module:parent:save")
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(Parent parent)
	{
		if (parentService.saveParent(parent) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除家长
	 */
	@RequiresPermissions("module:parent:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = parentService.deleteParentByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
